layui.use(['layer', 'form', 'table', 'admin', 'ax'], function () {
    var $ = layui.$;
    var layer = layui.layer;
    var form = layui.form;
    var table = layui.table;
    var $ax = layui.ax;
    var admin = layui.admin;

    /**
     * 系统管理--会员管理
     */
    var Integralrecord = {
        tableId: "IntegralrecordTable",    //表格id

    };




    /**
     * 点击查询按钮
     */
    Integralrecord.search = function () {
        var queryData = {};
        queryData['nickname'] = $("#nickname").val();
        queryData['status'] = $("#status").val();
        table.reload(Integralrecord.tableId, {where: queryData});
    };

    // 搜索按钮点击事件
    $('#btnSearch').click(function () {
        Integralrecord.search();
    });

    /**
     * 弹出添加积分
     */
    Integralrecord.openAddIntegralrecord = function () {
        admin.putTempData('formOk', false);
        top.layui.admin.open({
            type: 2,
            title: '添加字典类型',
            content: Feng.ctxPath + '/Integralrecord/IntegralrecordAdd',
            //结束时事件
            end: function () {
                admin.getTempData('formOk') && table.reload(Integralrecord.tableId);
            }
        });
    };

    // 添加按钮点击事件
    $('#btnAdd').click(function () {
        Integralrecord.openAddIntegralrecord();
    });

    /**
     * 点击编辑积分
     *
     * @param data 点击按钮时候的行数据
     */
    Integralrecord.onEditIntegralrecord = function (data) {
        admin.putTempData('formOk', false);
        top.layui.admin.open({
            type: 2,
            title: '积分详情',
            content: Feng.ctxPath + '/Integralrecord/Integralrecord_update?integralid=' + data.integralid,
            end: function () {
                admin.getTempData('formOk') && table.reload(Integralrecord.tableId);
            }
        });
    };

    /**
     * 点击删除积分
     *
     * @param data 点击按钮时候的行数据
     */
    Integralrecord.onDeleteIld = function (data) {
        var operation = function () {
            var ajax = new $ax(Feng.ctxPath + "/Integralrecord/delete", function (data) {
                Feng.success("删除成功!");
                table.reload(Integralrecord.tableId);
            }, function (data) {
                Feng.error("删除失败!" + data.responseJSON.message + "!");
            });
            ajax.set("integralid", data.integralid);
            ajax.start();
        };
        Feng.confirm("是否删除通知 " + data.title + "?", operation);
    };

    // 渲染表格
    var tableResult = table.render({
        elem: '#' + Integralrecord.tableId,
        url: Feng.ctxPath + '/Integralrecord/list',
        page: false,
        height: "full-158",
        cellMinWidth: 100,
        parseData: function(ilist){
            console.log(ilist);
            return{
                "code":0,
                "msg":"",
                "count":1000,
                data:ilist
            }
        },
        cols: [[
            {type:  'checkbox'},
            {field: 'integralrecord', hide: true, sort: true, title: '积分记录编号'},
            {templet: '<div>{{(d.tborderproductList[0].name)}}</div>', sort: true, title: '商品名称'},
            {field: 'getintegral', sort: true, title: '获得积分'},
            {field: 'useintegral', sort: true, title: '使用积分'},
            {field: 'createtime', sort: true, title: '创建时间'},
            {field: 'tplye', sort: true, title: '积分类型', templet: function (data) {
                                                                    if (data.tplye==0){
                                                                        return "增加积分";
                                                                    }else if (data.tplye==1){
                                                                        return "兑换优惠券使用";
                                                                    }else if (data.tplye==2){
                                                                        return "提现使用";
                                                                    }
                                                            }
                },
            {field: 'staty', sort: true, title: '积分状态', templet: function (data) {
                                                                if (data.staty==0){
                                                                    return "未确认";
                                                                }else if (data.staty==1){
                                                                    return "已确认";
                                                                }
                                                            }
                },
            {templet: '<div>{{(d.tbuserList[0].nickname)}}</div>', sort: true, title: '昵称'},
            {align: 'center', toolbar: '#tableBar', title: '操作', minWidth: 200}
        ]]

    });

    // 工具条点击事件
    table.on('tool(' + Integralrecord.tableId + ')', function (obj) {
        var data = obj.data;
        var layEvent = obj.event;

        if (layEvent === 'edit') {
            Integralrecord.onEditIntegralrecord(data);
        } else if (layEvent === 'delete') {
            Integralrecord.onDeleteIld(data);
        }
    });



});
